package org.example.petitionplatformsystem.service.Impl;




import org.example.petitionplatformsystem.dao.DepartmentsRepository;
import org.example.petitionplatformsystem.dao.model.Departments;
import org.example.petitionplatformsystem.service.DepartmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DepartmentsServiceImpl implements DepartmentsService {
    @Autowired
    private DepartmentsRepository departmentsRepository;;
    @Override
    public Departments AddDepartments(Departments departments) {
        return departmentsRepository.save(departments);
    }

    @Override
    public void DeleteDepartments(long DepartmentsId) {
        departmentsRepository.deleteById(DepartmentsId);
    }

    @Override
    public Departments UpdateDepartments(Departments departments) {
        return departmentsRepository.save(departments);
    }

    @Override
    public List<Departments> GetAllDepartments() {
        return departmentsRepository.findAll();
    }

    @Override
    public Departments GetADepartment(Long DepartmentId, Long InstitutionId) {
        return departmentsRepository.findByIdAndInstitutionId(DepartmentId, InstitutionId)
                .orElse(null);
    }


}
